
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>dispersed_phases &#8212; Texas A&amp;M Oil spill / Outfall Calculator 2.1.0 documentation</title>
    <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <h1>Source code for dispersed_phases</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Dispersed Phases</span>
<span class="sd">================</span>

<span class="sd">Create several objects and functions to manipulate dispersed phase particles</span>

<span class="sd">The `single_bubble_model`, `stratified_plume_model`, and `bent_plume_model` </span>
<span class="sd">all must handle dispersed phase particles in several different ways.  This </span>
<span class="sd">module defines several particle classes that provide seamless interfaces to</span>
<span class="sd">the `dbm` module.  It also defines several functions that aid in manipulating</span>
<span class="sd">common input data to create the inputs needed to initialize these particle</span>
<span class="sd">classes.  These classes and functions originated in the older versions of</span>
<span class="sd">the `single_bubble_model` and `stratified_plume_model`.  This module is a </span>
<span class="sd">re-factorization of these modules during creation of the `bent_plume_model`, </span>
<span class="sd">which allows all particle manipulations to reside in one place.</span>

<span class="sd">Notes </span>
<span class="sd">----- </span>
<span class="sd">These class objects and helper functions are used throughout the TAMOC </span>
<span class="sd">modeling suite. </span>

<span class="sd">See Also</span>
<span class="sd">--------</span>
<span class="sd">`stratified_plume_model` : Predicts the plume solution for quiescent ambient</span>
<span class="sd">    conditions or weak crossflows, where the intrusion (outer plume) </span>
<span class="sd">    interacts with the upward rising plume in a double-plume integral model</span>
<span class="sd">    approach.  Such a situation is handeled properly in the </span>
<span class="sd">    `stratified_plume_model` and would violate the assumption of non-</span>
<span class="sd">    iteracting Lagrangian plume elements as required in this module.</span>

<span class="sd">`single_bubble_model` : Tracks the trajectory of a single bubble, drop or </span>
<span class="sd">    particle through the water column.  The numerical solution, including</span>
<span class="sd">    the various object types and their functionality, used here follows the</span>
<span class="sd">    pattern in the `single_bubble_model`.  The main difference is the more</span>
<span class="sd">    complex state space and governing equations.</span>

<span class="sd">`bent_plume_model` : Simulates a multiphase plume as a Lagrangian plume </span>
<span class="sd">    model, which makes the model much more amenable to a crossflow.  This </span>
<span class="sd">    model is similar to the `stratified_plume_model`, except that it does</span>
<span class="sd">    not have an outer plume that interacts with the inner plume (Lagrangian</span>
<span class="sd">    elements are independent).  </span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="c1"># S. Socolofsky, October 2014, Texas A&amp;M University &lt;socolofs@tamu.edu&gt;.</span>

<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="p">(</span><span class="n">absolute_import</span><span class="p">,</span> <span class="n">division</span><span class="p">,</span> <span class="n">print_function</span><span class="p">)</span>

<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">seawater</span>
<span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">dbm</span>

<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">scipy.optimize</span> <span class="kn">import</span> <span class="n">fsolve</span>
<span class="kn">import</span> <span class="nn">unicodedata</span>
<span class="kn">from</span> <span class="nn">copy</span> <span class="kn">import</span> <span class="n">copy</span>


<span class="c1"># ----------------------------------------------------------------------------</span>
<span class="c1"># Define the Particle objects for the multiphase behavior in the TAMOC models</span>
<span class="c1"># ----------------------------------------------------------------------------</span>

<div class="viewcode-block" id="SingleParticle"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.SingleParticle.html#dispersed_phases.SingleParticle">[docs]</a><span class="k">class</span> <span class="nc">SingleParticle</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Interface to the `dbm` module and container for model parameters</span>
<span class="sd">    </span>
<span class="sd">    This class provides a uniform interface to the `dbm` module objects and</span>
<span class="sd">    methods and stores the particle-specific model parameters.  Because the</span>
<span class="sd">    methods for `dbm.FluidParticle` and `dbm.InsolubleParticle` sometimes have </span>
<span class="sd">    different inputs and different outputs, there needs to be a method to </span>
<span class="sd">    support these interface differences in a single location.  This object</span>
<span class="sd">    solves that problem by providing a single interface and uniform outputs</span>
<span class="sd">    for the particle properties needed by the single bubble model.  This also</span>
<span class="sd">    affords a convenient place to store the particle-specific model </span>
<span class="sd">    parameters and behavior, such as mass transfer reduction factor, etc., </span>
<span class="sd">    turning off heat transfer once the particle matches the ambient </span>
<span class="sd">    temperature and turning off the particle buoyancy once the particle is</span>
<span class="sd">    dissolved.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    dbm_particle : `dbm.FluidParticle` or `dbm.InsolubleParticle` object</span>
<span class="sd">        Object describing the particle properties and behavior</span>
<span class="sd">    m0 : ndarray</span>
<span class="sd">        Initial masses of the components of the `dbm` particle object (kg)</span>
<span class="sd">    T0 : float</span>
<span class="sd">        Initial temperature of the of `dbm` particle object (K)</span>
<span class="sd">    K : float, default = 1.</span>
<span class="sd">        Mass transfer reduction factor (--).</span>
<span class="sd">    K_T : float, default = 1.</span>
<span class="sd">        Heat transfer reduction factor (--).</span>
<span class="sd">    fdis : float, default = 1e-6</span>
<span class="sd">        Fraction of the initial total mass (--) remaining when the particle </span>
<span class="sd">        should be considered dissolved.</span>
<span class="sd">    t_hyd : float, default = 0.</span>
<span class="sd">        Hydrate film formation time (s).  Mass transfer is computed by clean</span>
<span class="sd">        bubble methods for t less than t_hyd and by dirty bubble methods</span>
<span class="sd">        thereafter.  The default behavior is to assume the particle is dirty</span>
<span class="sd">        or hydrate covered from the release.</span>
<span class="sd">    lag_time : bool, default = True.</span>
<span class="sd">        Flag that indicates whether (True) or not (False) to use the</span>
<span class="sd">        biodegradation lag times data.</span>
<span class="sd">    </span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    particle : `dbm.FluidParticle` or `dbm.InsolubleParticle` object</span>
<span class="sd">        Stores the `dbm_particle` object passed to `__init__()`.</span>
<span class="sd">    composition : str list</span>
<span class="sd">        Copy of the `composition` attribute of the `dbm_particle` object.</span>
<span class="sd">    m0 : ndarray</span>
<span class="sd">        Initial masses (kg) of the particle components</span>
<span class="sd">    T0 : float</span>
<span class="sd">        Initial temperature (K) of the particle</span>
<span class="sd">    cp : float</span>
<span class="sd">        Heat capacity at constant pressure (J/(kg K)) of the particle.</span>
<span class="sd">    K : float</span>
<span class="sd">        Mass transfer reduction factor (--)</span>
<span class="sd">    K_T : float</span>
<span class="sd">        Heat transfer reduction factor (--)</span>
<span class="sd">    fdis : float</span>
<span class="sd">        Fraction of initial mass remaining as total dissolution (--)</span>
<span class="sd">    diss_indices : ndarray bool</span>
<span class="sd">        Indices of m0 that are non-zero.</span>
<span class="sd">    </span>
<span class="sd">    Notes</span>
<span class="sd">    -----</span>
<span class="sd">    This object only provides an interface to the `return_all` and </span>
<span class="sd">    `diameter` methods of the `dbm` module objects.  The intent is to be as </span>
<span class="sd">    fast as possible while providing a single location for the necessary </span>
<span class="sd">    `if`-statements needed to select between soluble and insoluble particle </span>
<span class="sd">    methods and facilitate turning heat transfer and dissolution on and off</span>
<span class="sd">    as necessary at the simulation progresses.  </span>
<span class="sd">    </span>
<span class="sd">    Dissolution is turned off component by component as each components mass</span>
<span class="sd">    becomes fdis times smaller than the initial mass.  Once all of the initial</span>
<span class="sd">    components have been turned off, the particle is assumed to have a </span>
<span class="sd">    density equation to the ambient water and a slip velocity of zero.</span>
<span class="sd">    </span>
<span class="sd">    Heat transfer is turned off once the particle comes within 0.1 K of the</span>
<span class="sd">    ambient temperature.  Thereafter, the temperature is forced to track </span>
<span class="sd">    the ambient temperature.</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="SingleParticle.__init__"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.SingleParticle.html#dispersed_phases.SingleParticle.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dbm_particle</span><span class="p">,</span> <span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">K</span><span class="o">=</span><span class="mf">1.</span><span class="p">,</span> <span class="n">K_T</span><span class="o">=</span><span class="mf">1.</span><span class="p">,</span> <span class="n">fdis</span><span class="o">=</span><span class="mf">1.e-6</span><span class="p">,</span> 
                 <span class="n">t_hyd</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">lag_time</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">SingleParticle</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">()</span>
        
        <span class="c1"># Make sure the masses are in a numpy array</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">m0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">m0</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
                <span class="n">m0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">m0</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">m0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">m0</span><span class="p">)</span>
        
        <span class="c1"># Store the input parameters</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">particle</span> <span class="o">=</span> <span class="n">dbm_particle</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">composition</span> <span class="o">=</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">composition</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m0</span> <span class="o">=</span> <span class="n">m0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">T0</span> <span class="o">=</span> <span class="n">T0</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">cp</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">cp</span><span class="p">()</span> <span class="o">*</span> <span class="mf">0.5</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lag_time</span> <span class="o">=</span> <span class="n">lag_time</span>
        
        <span class="c1"># Store the particle-specific model parameters</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">K</span> <span class="o">=</span> <span class="n">K</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">K_T</span> <span class="o">=</span> <span class="n">K_T</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">fdis</span> <span class="o">=</span> <span class="n">fdis</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">t_hyd</span> <span class="o">=</span> <span class="n">t_hyd</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lag_time</span> <span class="o">=</span> <span class="n">lag_time</span>
        
        <span class="c1"># Store parameters to track the dissolution of the initial masses</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">diss_indices</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">m0</span> <span class="o">&gt;</span> <span class="mi">0</span></div>
    
<div class="viewcode-block" id="SingleParticle.properties"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.SingleParticle.properties.html#dispersed_phases.SingleParticle.properties">[docs]</a>    <span class="k">def</span> <span class="nf">properties</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Return the particle properties from the discrete bubble model</span>
<span class="sd">        </span>
<span class="sd">        Provides a single interface to the `return_all` methods of the fluid </span>
<span class="sd">        and insoluble particle objects defined in the `dbm` module.  </span>
<span class="sd">        This method also applies the particle-specific model parameters to </span>
<span class="sd">        adjust the mass and heat transfer and determine the dissolution state.</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        m : float</span>
<span class="sd">             mass of the particle (kg)</span>
<span class="sd">        T : float</span>
<span class="sd">             particle temperature (K)</span>
<span class="sd">        P : float</span>
<span class="sd">            particle pressure (Pa)</span>
<span class="sd">        Sa : float</span>
<span class="sd">            salinity of ambient seawater (psu)</span>
<span class="sd">        Ta : float</span>
<span class="sd">            temperature of ambient seawater (K)</span>
<span class="sd">        t : float</span>
<span class="sd">            age of the particle--time since it was released into the water </span>
<span class="sd">            column (s)</span>
<span class="sd">        </span>
<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        A tuple containing:</span>
<span class="sd">            </span>
<span class="sd">            us : float</span>
<span class="sd">                slip velocity (m/s)</span>
<span class="sd">            rho_p : float</span>
<span class="sd">                particle density (kg/m^3)</span>
<span class="sd">            A : float </span>
<span class="sd">                surface area (m^2)</span>
<span class="sd">            Cs : ndarray, size (nc)</span>
<span class="sd">                solubility (kg/m^3)</span>
<span class="sd">            K * beta : ndarray, size (nc)</span>
<span class="sd">                effective mass transfer coefficient(s) (m/s)</span>
<span class="sd">            K_T * beta_T : float</span>
<span class="sd">                effective heat transfer coefficient (m/s)</span>
<span class="sd">            T : float</span>
<span class="sd">                temperature of the particle (K)</span>
<span class="sd">        </span>
<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        For insoluble particles, `Cs` and `beta` are undefined.  This method</span>
<span class="sd">        returns values for these variables that will result in no </span>
<span class="sd">        dissolution and will also protect model simulations from undefined</span>
<span class="sd">        mathematical operations (e.g., divide by zero).</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Turn off heat transfer when at equilibrium.  This will be a </span>
        <span class="c1"># persistent change, so it only has to happen once.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">K_T</span> <span class="o">&gt;</span> <span class="mf">0.</span> <span class="ow">and</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">Ta</span> <span class="o">-</span> <span class="n">T</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mf">0.5</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">K_T</span> <span class="o">=</span> <span class="mf">0.</span>
        
        <span class="c1"># Use the right temperature</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">K_T</span> <span class="o">==</span> <span class="mf">0.</span><span class="p">:</span>
            <span class="n">T</span> <span class="o">=</span> <span class="n">Ta</span>
        
        <span class="c1"># Decide which slip velocity and mass and heat transfer to use</span>
        <span class="k">if</span> <span class="n">t</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">t_hyd</span><span class="p">:</span>
            <span class="c1"># Treat the particle as clean for slip velocity and mass</span>
            <span class="c1"># transfer</span>
            <span class="n">status</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Use the dirty bubble slip velocity and mass transfer</span>
            <span class="n">status</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
        
        <span class="c1"># Distinguish between soluble and insoluble particles</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">issoluble</span><span class="p">:</span>
                        
            <span class="c1"># Get the DBM results</span>
            <span class="n">m</span><span class="p">[</span><span class="n">m</span><span class="o">&lt;</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.</span>   <span class="c1"># stop oscillations at small mass</span>
            <span class="n">shape</span><span class="p">,</span> <span class="n">de</span><span class="p">,</span> <span class="n">rho_p</span><span class="p">,</span> <span class="n">us</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">Cs</span><span class="p">,</span> <span class="n">beta</span><span class="p">,</span> <span class="n">beta_T</span> <span class="o">=</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">return_all</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="n">status</span><span class="p">)</span>
            
            <span class="c1"># Turn off dissolution for &quot;dissolved&quot; components</span>
            <span class="n">frac_diss</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">size</span><span class="p">(</span><span class="n">m</span><span class="p">))</span>
            <span class="n">frac_diss</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">diss_indices</span><span class="p">]</span> <span class="o">=</span> \
                <span class="n">m</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">diss_indices</span><span class="p">]</span> <span class="o">/</span> <span class="bp">self</span><span class="o">.</span><span class="n">m0</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">diss_indices</span><span class="p">]</span>
            <span class="n">beta</span><span class="p">[</span><span class="n">frac_diss</span> <span class="o">&lt;</span> <span class="bp">self</span><span class="o">.</span><span class="n">fdis</span><span class="p">]</span> <span class="o">=</span> <span class="mf">0.</span>
            
            <span class="c1"># Shut down bubble forces when particles fully dissolve</span>
            <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">beta</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">diss_indices</span><span class="p">])</span> <span class="o">==</span> <span class="mf">0.</span><span class="p">:</span>
                <span class="c1"># Injected chemicals have dissolved</span>
                <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">diss_indices</span><span class="p">])</span> <span class="o">&gt;</span> \
                    <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="o">~</span><span class="bp">self</span><span class="o">.</span><span class="n">diss_indices</span><span class="p">]):</span>
                    <span class="c1"># The whole particle has dissolved</span>
                    <span class="n">us</span> <span class="o">=</span> <span class="mf">0.0</span>
                    <span class="n">rho_p</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span><span class="p">)</span>
        
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># Get the particle properties</span>
            <span class="n">shape</span><span class="p">,</span> <span class="n">de</span><span class="p">,</span> <span class="n">rho_p</span><span class="p">,</span> <span class="n">us</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">beta_T</span> <span class="o">=</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">return_all</span><span class="p">(</span><span class="n">m</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="n">status</span><span class="p">)</span>
            <span class="n">beta</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([])</span>
            <span class="n">Cs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([])</span>
        
        <span class="c1"># Return the particle properties</span>
        <span class="k">return</span> <span class="p">(</span><span class="n">us</span><span class="p">,</span> <span class="n">rho_p</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">Cs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">K</span> <span class="o">*</span> <span class="n">beta</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">K_T</span> <span class="o">*</span> <span class="n">beta_T</span><span class="p">,</span> <span class="n">T</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="SingleParticle.diameter"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.SingleParticle.diameter.html#dispersed_phases.SingleParticle.diameter">[docs]</a>    <span class="k">def</span> <span class="nf">diameter</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the diameter of a particle from mass and density</span>
<span class="sd">        </span>
<span class="sd">        Computes the diameter of a particle using the methods in the `dbm`</span>
<span class="sd">        module.  This method is used in the post-processor of the `Model`</span>
<span class="sd">        object, but not in the actual simulation.  </span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        m : float</span>
<span class="sd">             mass of the particle (kg)</span>
<span class="sd">        T : float</span>
<span class="sd">             particle temperature (K)</span>
<span class="sd">        P : float</span>
<span class="sd">            particle pressure (Pa)</span>
<span class="sd">        Sa : float</span>
<span class="sd">            salinity of ambient seawater (psu)</span>
<span class="sd">        Ta : float</span>
<span class="sd">            temperature of ambient seawater (K)</span>
<span class="sd">        </span>
<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        de : float</span>
<span class="sd">            diameter of the particle (m)</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Distinguish between soluble and insoluble particles</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">issoluble</span><span class="p">:</span>
            <span class="n">de</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">diameter</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">de</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">diameter</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">)</span>
        
        <span class="c1"># Return the diameter</span>
        <span class="k">return</span> <span class="n">de</span></div>
    
<div class="viewcode-block" id="SingleParticle.biodegradation_rate"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.SingleParticle.biodegradation_rate.html#dispersed_phases.SingleParticle.biodegradation_rate">[docs]</a>    <span class="k">def</span> <span class="nf">biodegradation_rate</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the biodegradation rate constants</span>
<span class="sd">        </span>
<span class="sd">        Computes the biodegradation rate constants using the method in the</span>
<span class="sd">        `dbm` module.  </span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        t : float</span>
<span class="sd">            current simulation time (s)</span>
<span class="sd">        </span>
<span class="sd">        Returns</span>
<span class="sd">        -------</span>
<span class="sd">        k_bio : ndarray, size (nc)</span>
<span class="sd">            first-order biodegradation rate constants (1/s)</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">biodegradation_rate</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">lag_time</span><span class="p">)</span></div></div>


<div class="viewcode-block" id="PlumeParticle"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.PlumeParticle.html#dispersed_phases.PlumeParticle">[docs]</a><span class="k">class</span> <span class="nc">PlumeParticle</span><span class="p">(</span><span class="n">SingleParticle</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Interface to the `dbm` module and container for the model parameters</span>
<span class="sd">    </span>
<span class="sd">    As in the `single_bubble_model.Particle` class, this object provides a</span>
<span class="sd">    uniform interface to the `dbm` module objects and captures the </span>
<span class="sd">    particle-specific model parameters.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    dbm_particle : `dbm.FluidParticle` or `dbm.InsolubleParticle` object</span>
<span class="sd">        Object describing the particle properties and behavior</span>
<span class="sd">    m0 : ndarray</span>
<span class="sd">        Initial masses of one particle for the components of the </span>
<span class="sd">        `dbm_particle` object (kg)</span>
<span class="sd">    T0 : float</span>
<span class="sd">        Initial temperature of the of `dbm` particle object (K)</span>
<span class="sd">    nb0 : float</span>
<span class="sd">        Initial number flux of particles at the release (--)</span>
<span class="sd">    lambda_1 : float </span>
<span class="sd">        spreading rate of the dispersed phase in a plume (--)</span>
<span class="sd">    P : float</span>
<span class="sd">        Local pressure (Pa)</span>
<span class="sd">    Sa : float</span>
<span class="sd">        Local salinity surrounding the particle (psu)</span>
<span class="sd">    Ta : float</span>
<span class="sd">        Local temperature surrounding the particle (K)</span>
<span class="sd">    K : float, default = 1.</span>
<span class="sd">        Mass transfer reduction factor (--).</span>
<span class="sd">    K_T : float, default = 1.</span>
<span class="sd">        Heat transfer reduction factor (--).</span>
<span class="sd">    fdis : float, default = 0.01</span>
<span class="sd">        Fraction of the initial total mass (--) remaining when the particle </span>
<span class="sd">        should be considered dissolved.</span>
<span class="sd">    t_hyd : float, default = 0.</span>
<span class="sd">        Hydrate film formation time (s).  Mass transfer is computed by clean</span>
<span class="sd">        bubble methods for t less than t_hyd and by dirty bubble methods</span>
<span class="sd">        thereafter.  The default behavior is to assume the particle is dirty</span>
<span class="sd">        or hydrate covered from the release.</span>
<span class="sd">    lag_time : bool, default = True.</span>
<span class="sd">        Flag that indicates whether (True) or not (False) to use the</span>
<span class="sd">        biodegradation lag times data.</span>
<span class="sd">    </span>
<span class="sd">    </span>
<span class="sd">    Attributes</span>
<span class="sd">    ----------</span>
<span class="sd">    particle : `dbm.FluidParticle` or `dbm.InsolubleParticle` object</span>
<span class="sd">        Stores the `dbm_particle` object passed to `__init__()`.</span>
<span class="sd">    composition : str list</span>
<span class="sd">        Copy of the `composition` attribute of the `dbm_particle` object.</span>
<span class="sd">    m0 : ndarray</span>
<span class="sd">        Initial masses (kg) of the particle components</span>
<span class="sd">    T0 : float</span>
<span class="sd">        Initial temperature (K) of the particle</span>
<span class="sd">    cp : float</span>
<span class="sd">        Heat capacity at constant pressure (J/(kg K)) of the particle.</span>
<span class="sd">    K : float</span>
<span class="sd">        Mass transfer reduction factor (--)</span>
<span class="sd">    K_T : float</span>
<span class="sd">        Heat transfer reduction factor (--)</span>
<span class="sd">    fdis : float</span>
<span class="sd">        Fraction of initial mass remaining as total dissolution (--)</span>
<span class="sd">    diss_indices : ndarray bool</span>
<span class="sd">        Indices of m0 that are non-zero.</span>
<span class="sd">    nb0 : float</span>
<span class="sd">        Initial number flux of particles at the release (--)</span>
<span class="sd">    lambda_1 : float </span>
<span class="sd">        Spreading rate of the dispersed phase in a plume (--)</span>
<span class="sd">    m : ndarray</span>
<span class="sd">        Current masses of the particle components (kg)</span>
<span class="sd">    T : float</span>
<span class="sd">        Current temperature of the particle (K)</span>
<span class="sd">    us : float</span>
<span class="sd">        Slip velocity (m/s)</span>
<span class="sd">    rho_p : float</span>
<span class="sd">        Particle density (kg/m^3)</span>
<span class="sd">    A : float</span>
<span class="sd">        Particle surface area (m^2)</span>
<span class="sd">    Cs : ndarray</span>
<span class="sd">        Solubility of each dissolving component in the particle (kg/m^3)</span>
<span class="sd">    beta : ndarray</span>
<span class="sd">        Mass transfer coefficients (m/s)</span>
<span class="sd">    beta_T : float</span>
<span class="sd">        Heat transfer coefficient (m/s)</span>
<span class="sd">    </span>
<span class="sd">    See Also</span>
<span class="sd">    --------</span>
<span class="sd">    single_bubble_model.Particle</span>
<span class="sd">    </span>
<span class="sd">    Notes</span>
<span class="sd">    -----</span>
<span class="sd">    This object inherits the `single_bubble_model.Particle` object, which</span>
<span class="sd">    defines the attributes: `particle`, `composition`, `m0`, `T0`, `cp`, </span>
<span class="sd">    `K`, `K_T`, `fdis`, and `diss_indices` and the methods</span>
<span class="sd">    `single_bubble_model.Particle.properties`, and </span>
<span class="sd">    `single_bubble_model.Particle.diameter`.</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
<div class="viewcode-block" id="PlumeParticle.__init__"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.PlumeParticle.html#dispersed_phases.PlumeParticle.__init__">[docs]</a>    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dbm_particle</span><span class="p">,</span> <span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">nb0</span><span class="p">,</span> <span class="n">lambda_1</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> 
                 <span class="n">K</span><span class="o">=</span><span class="mf">1.</span><span class="p">,</span> <span class="n">K_T</span><span class="o">=</span><span class="mf">1.</span><span class="p">,</span> <span class="n">fdis</span><span class="o">=</span><span class="mf">1.e-6</span><span class="p">,</span> <span class="n">t_hyd</span><span class="o">=</span><span class="mf">0.</span><span class="p">,</span> <span class="n">lag_time</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">PlumeParticle</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span><span class="n">dbm_particle</span><span class="p">,</span> <span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">K</span><span class="p">,</span> <span class="n">K_T</span><span class="p">,</span> 
                                            <span class="n">fdis</span><span class="p">,</span> <span class="n">t_hyd</span><span class="p">,</span> <span class="n">lag_time</span><span class="p">)</span>
        
        <span class="c1"># Store the input variables related to the particle description</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nb0</span> <span class="o">=</span> <span class="n">nb0</span>
        
        <span class="c1"># Store the model parameters</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">lambda_1</span> <span class="o">=</span> <span class="n">lambda_1</span>
        
        <span class="c1"># Set the local masses and temperature to their initial values.  The</span>
        <span class="c1"># particle age is zero at instantiation</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="mf">0.</span><span class="p">)</span></div>
    
<div class="viewcode-block" id="PlumeParticle.update"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.PlumeParticle.update.html#dispersed_phases.PlumeParticle.update">[docs]</a>    <span class="k">def</span> <span class="nf">update</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Store the instantaneous values of the particle properties</span>
<span class="sd">        </span>
<span class="sd">        During the simulation, it is often helpful to keep the state space</span>
<span class="sd">        variables for each particle stored within the particle, especially</span>
<span class="sd">        since each particle type (soluble or insoluble) can have different</span>
<span class="sd">        sizes of arrays for m.</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        m : ndarray</span>
<span class="sd">            Current masses (kg) of the particle components</span>
<span class="sd">        T : float</span>
<span class="sd">            Current temperature (K) of the particle</span>
<span class="sd">        P : float</span>
<span class="sd">            Local pressure (Pa)</span>
<span class="sd">        Sa : float</span>
<span class="sd">            Local salinity surrounding the particle (psu)</span>
<span class="sd">        Ta : float</span>
<span class="sd">            Local temperature surrounding the particle (K)       </span>
<span class="sd">        t : float</span>
<span class="sd">            age of the particle--time since it was released into the water </span>
<span class="sd">            column (s)</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Make sure the masses are in a numpy array</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">m</span><span class="p">])</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        
        <span class="c1"># Update the variables with their currrent values</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">m</span> <span class="o">=</span> <span class="n">m</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">m</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mf">0.</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">us</span><span class="p">,</span>  <span class="bp">self</span><span class="o">.</span><span class="n">rho_p</span><span class="p">,</span>  <span class="bp">self</span><span class="o">.</span><span class="n">A</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">Cs</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">beta</span><span class="p">,</span> \
                <span class="bp">self</span><span class="o">.</span><span class="n">beta_T</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">T</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">properties</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">k_bio</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">biodegradation_rate</span><span class="p">(</span><span class="n">t</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">us</span> <span class="o">=</span> <span class="mf">0.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">rho_p</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span><span class="p">)</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">A</span> <span class="o">=</span> <span class="mf">0.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">Cs</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">composition</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">beta</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">composition</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">beta_T</span> <span class="o">=</span> <span class="mf">0.</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">T</span> <span class="o">=</span> <span class="n">Ta</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">k_bio</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">composition</span><span class="p">))</span></div></div>


<span class="c1"># ----------------------------------------------------------------------------</span>
<span class="c1"># Functions that help to create SingleParticle and PlumeParticle objects</span>
<span class="c1"># ----------------------------------------------------------------------------</span>

<div class="viewcode-block" id="initial_conditions"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.initial_conditions.html#dispersed_phases.initial_conditions">[docs]</a><span class="k">def</span> <span class="nf">initial_conditions</span><span class="p">(</span><span class="n">profile</span><span class="p">,</span> <span class="n">z0</span><span class="p">,</span> <span class="n">dbm_particle</span><span class="p">,</span> <span class="n">yk</span><span class="p">,</span> <span class="n">q</span><span class="p">,</span> <span class="n">q_type</span><span class="p">,</span> <span class="n">de</span><span class="p">,</span> 
                       <span class="n">T0</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Define standard initial conditions for a PlumeParticle from flow rate</span>
<span class="sd">    </span>
<span class="sd">    Returns the standard variables describing a particle as needed to </span>
<span class="sd">    initializae a PlumeParticle object from specification of the dispersed phase</span>
<span class="sd">    flow rate.  </span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the simulation.</span>
<span class="sd">    z0 : float</span>
<span class="sd">        Depth of the release point (m)</span>
<span class="sd">    dbm_particle : `dbm.FluidParticle` or `dbm.InsolubleParticle` object</span>
<span class="sd">        Object describing the particle properties and behavior</span>
<span class="sd">    yk : ndarray</span>
<span class="sd">        Vector of mol fractions of each component of the dispersed phase </span>
<span class="sd">        particle.  If the particle is a `dbm.InsolubleParticle`, then yk </span>
<span class="sd">        should be equal to one.</span>
<span class="sd">    q : float</span>
<span class="sd">        Flux of the dispersed phase, either as the volume flux (m^3/s) at </span>
<span class="sd">        standard conditions, defined as 0 deg C and 1 bar, or as mass flux </span>
<span class="sd">        (kg/s).</span>
<span class="sd">    q_type : int</span>
<span class="sd">        Determines the type of flux units.  0: we want the mass of a single </span>
<span class="sd">        particle (hence q = None since it is currently unknown), 1: q is </span>
<span class="sd">        volume flux, 2: q is mass flux</span>
<span class="sd">    de : float</span>
<span class="sd">        Initial diameter (m) of the particle</span>
<span class="sd">    T0 : float, default = None</span>
<span class="sd">        Initial temperature of the of `dbm` particle object (K).  If None, </span>
<span class="sd">        then T0 is set equal to the ambient temperature.</span>
<span class="sd">    </span>
<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    m0 : ndarray</span>
<span class="sd">        Initial masses of the components of one particle in the `dbm` </span>
<span class="sd">        particle object (kg)</span>
<span class="sd">    T0 : float</span>
<span class="sd">        Initial temperature of the of `dbm` particle object (K)</span>
<span class="sd">    nb0 : float</span>
<span class="sd">        Initial number flux of particles at the release (--)</span>
<span class="sd">    P : float</span>
<span class="sd">        Local pressure (Pa)</span>
<span class="sd">    Sa : float</span>
<span class="sd">        Local salinity surrounding the particle (psu)</span>
<span class="sd">    Ta : float</span>
<span class="sd">        Local temperature surrounding the particle (K)</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Make sure yk is an array</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">yk</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">yk</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
            <span class="n">yk</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">yk</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">yk</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">yk</span><span class="p">)</span>
    
    <span class="c1"># Get the ambient conditions at the release</span>
    <span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="n">z0</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;temperature&#39;</span><span class="p">,</span> <span class="s1">&#39;salinity&#39;</span><span class="p">,</span> 
                                        <span class="s1">&#39;pressure&#39;</span><span class="p">])</span>
    
    <span class="c1"># Get the particle temperature</span>
    <span class="k">if</span> <span class="n">T0</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">T0</span> <span class="o">=</span> <span class="n">copy</span><span class="p">(</span><span class="n">Ta</span><span class="p">)</span>
    
    <span class="c1"># Compute the density at standard and in situ conditions</span>
    <span class="k">if</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">issoluble</span><span class="p">:</span>
        <span class="n">mf</span> <span class="o">=</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">mass_frac</span><span class="p">(</span><span class="n">yk</span><span class="p">)</span>
        <span class="n">rho_N</span> <span class="o">=</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="mf">273.15</span><span class="p">,</span> <span class="mf">1.e5</span><span class="p">)</span>
        <span class="n">rho_p</span> <span class="o">=</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">mf</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">P</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">mf</span> <span class="o">=</span> <span class="mf">1.</span>
        <span class="n">rho_N</span> <span class="o">=</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="mf">273.15</span><span class="p">,</span> <span class="mf">1.e5</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">273.15</span><span class="p">)</span>
        <span class="n">rho_p</span> <span class="o">=</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">T0</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">)</span>
    
    <span class="c1"># Get the mass and number flux of particles</span>
    <span class="k">if</span> <span class="n">q_type</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="c1"># Compute the mass flux of a single particle from the given diameter</span>
        <span class="k">if</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">issoluble</span><span class="p">:</span>
            <span class="n">m0</span> <span class="o">=</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">masses_by_diameter</span><span class="p">(</span><span class="n">de</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">yk</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">m0</span> <span class="o">=</span> <span class="n">dbm_particle</span><span class="o">.</span><span class="n">mass_by_diameter</span><span class="p">(</span><span class="n">de</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">)</span>
        <span class="n">nb0</span> <span class="o">=</span> <span class="mf">1.</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">q_type</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="c1"># Compute the total mass flux from the given volume flux at STP</span>
            <span class="n">m_dot</span> <span class="o">=</span> <span class="n">q</span> <span class="o">*</span> <span class="n">rho_N</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c1"># The input flux is the total mass flux</span>
            <span class="n">m_dot</span> <span class="o">=</span> <span class="n">q</span>
        
        <span class="c1"># Get the source volume flux and particle number flux</span>
        <span class="n">Q</span> <span class="o">=</span> <span class="n">m_dot</span> <span class="o">/</span> <span class="n">rho_p</span>
        <span class="n">nb0</span> <span class="o">=</span> <span class="n">Q</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">de</span><span class="o">**</span><span class="mi">3</span> <span class="o">/</span> <span class="mf">6.</span><span class="p">)</span>
        
        <span class="c1"># Get the initial particle mass(es)</span>
        <span class="n">m0</span> <span class="o">=</span> <span class="n">m_dot</span> <span class="o">/</span> <span class="n">nb0</span> <span class="o">*</span> <span class="n">mf</span>
    
    <span class="c1"># Return the standard variables</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">m0</span><span class="p">,</span> <span class="n">T0</span><span class="p">,</span> <span class="n">nb0</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">)</span></div>


<span class="c1"># ----------------------------------------------------------------------------</span>
<span class="c1"># Functions to save and load a particle to an open netCDF4 dataset</span>
<span class="c1"># ----------------------------------------------------------------------------</span>

<div class="viewcode-block" id="save_particle_to_nc_file"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.save_particle_to_nc_file.html#dispersed_phases.save_particle_to_nc_file">[docs]</a><span class="k">def</span> <span class="nf">save_particle_to_nc_file</span><span class="p">(</span><span class="n">nc</span><span class="p">,</span> <span class="n">chem_names</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">K_T0</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Write the particle attributes to a netCDF output file</span>
<span class="sd">    </span>
<span class="sd">    Writes all of the object attributes for a `SingleParticle` or </span>
<span class="sd">    `PlumeParticle` object to a netCDF output file.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    nc : `netCDF4.Dataset` object</span>
<span class="sd">        A `netCDF4.Dataset` object that is open and where the particle </span>
<span class="sd">        attributes should be written</span>
<span class="sd">    chem_names : str list</span>
<span class="sd">        A list of chemical names in the composition of the `dbm` objects</span>
<span class="sd">        in these particles</span>
<span class="sd">    particles : list of `Particle` objects</span>
<span class="sd">        List of `SingleParticle`, `PlumeParticle`, or </span>
<span class="sd">        `bent_plume_model.Particle` objects describing each dispersed phase </span>
<span class="sd">        in the simulation</span>
<span class="sd">    K_T0 : ndarray</span>
<span class="sd">        Array of the initial values of the heat transfer reduction factor.</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Make sure the particles variable is iterable</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">particles</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
        <span class="n">particles</span> <span class="o">=</span> <span class="p">[</span><span class="n">particles</span><span class="p">]</span>
    
    <span class="c1"># Make sure K_T0 is an array</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">K_T0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">K_T0</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
            <span class="n">K_T0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">K_T0</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">K_T0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">K_T0</span><span class="p">)</span>
    
    <span class="c1"># Count the number of particles</span>
    <span class="n">nparticles</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">))</span>
    <span class="n">ngroups</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;ngroups&#39;</span><span class="p">,</span> <span class="mi">15</span><span class="p">)</span>
    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">chem_names</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">nchems</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;nchems&#39;</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">chem_names</span><span class="p">))</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">nchems</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;nchems&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    <span class="n">num</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;num&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
    
    <span class="c1"># Save the particle composition</span>
    <span class="n">nc</span><span class="o">.</span><span class="n">composition</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">chem_names</span><span class="p">)</span>
    
    <span class="c1"># Create the dataset descriptions for all the particle variables</span>
    <span class="n">particle_type</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;particle_type&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;num&#39;</span><span class="p">,))</span>
    <span class="n">particle_type</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;dispersed_phases Particle type&#39;</span>
    <span class="n">particle_type</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;particle_type&#39;</span>
    <span class="n">particle_type</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;0: Single, 1:Plume, 2:Bent plume particle&#39;</span>
    
    <span class="n">issoluble</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;issoluble&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">issoluble</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;solubility (0: false, 1: true)&#39;</span>
    <span class="n">issoluble</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;issoluble&#39;</span>
    <span class="n">issoluble</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;boolean&#39;</span>
    
    <span class="n">isair</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;isair&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">isair</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;fluid is air (0: false, 1: true)&#39;</span>
    <span class="n">isair</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;isair&#39;</span>
    <span class="n">isair</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;boolean&#39;</span>
    
    <span class="n">isfluid</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;isfluid&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">isfluid</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;Fluid status (0: false, 1: true)&#39;</span>
    <span class="n">isfluid</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;isfluid&#39;</span>
    <span class="n">isfluid</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;boolean&#39;</span>
    
    <span class="n">iscompressible</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;iscompressible&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> 
                                       <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">iscompressible</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;Compressibility (0: false, 1: true)&#39;</span>
    <span class="n">iscompressible</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;iscompressible&#39;</span>
    <span class="n">iscompressible</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;boolean&#39;</span>
    
    <span class="n">calc_delta</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;calc_delta&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">calc_delta</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;Calculate delta (-1: false, 1: true)&#39;</span>
    <span class="n">calc_delta</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;calc_delta&#39;</span>
    <span class="n">calc_delta</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;boolean&#39;</span>
    
    <span class="n">extern_data</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;extern_data&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">extern_data</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;External chem database (0: false, 1: true)&#39;</span>
    <span class="n">extern_data</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;extern_data&#39;</span>
    <span class="n">extern_data</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;boolean&#39;</span>
    
    <span class="n">fp_type</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;fp_type&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">fp_type</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;fluid phase (0: gas, 1: liquid, 2: solid)&#39;</span>
    <span class="n">fp_type</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;fp_type&#39;</span>
    <span class="n">fp_type</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>
    
    <span class="n">rho_p</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;rho_p&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">rho_p</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;particle density&#39;</span>
    <span class="n">rho_p</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;rho_p&#39;</span>
    <span class="n">rho_p</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;kg/m^3&#39;</span>
    
    <span class="n">gamma</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;gamma&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">gamma</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;API Gravity&#39;</span>
    <span class="n">gamma</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;gamma&#39;</span>
    <span class="n">gamma</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;deg API&#39;</span>
    
    <span class="n">beta</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;beta&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">beta</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;thermal expansion coefficient&#39;</span>
    <span class="n">beta</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;beta&#39;</span>
    <span class="n">beta</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;Pa^(-1)&#39;</span>
    
    <span class="n">co</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;co&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">co</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;isothermal compressibility coefficient&#39;</span>
    <span class="n">co</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;co&#39;</span>
    <span class="n">co</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;K^(-1)&#39;</span>
        
    <span class="n">sigma_correction</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;sigma_correction&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> 
        <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">sigma_correction</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;interfacial tension reduction factor (--)&#39;</span>
    <span class="n">sigma_correction</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;sigma_correction&#39;</span>
    <span class="n">sigma_correction</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>
    
    <span class="n">delta_groups</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;delta_groups&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> 
        <span class="s1">&#39;nchems&#39;</span><span class="p">,</span> <span class="s1">&#39;ngroups&#39;</span><span class="p">))</span>
    <span class="n">delta_groups</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;group contribution method delta groups&#39;</span>
    <span class="n">delta_groups</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;delta_groups&#39;</span>
    <span class="n">delta_groups</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>
    
    <span class="n">m0</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;m0&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;nchems&#39;</span><span class="p">))</span>
    <span class="n">m0</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;initial mass flux&#39;</span>
    <span class="n">m0</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;m0&#39;</span>
    <span class="n">m0</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;kg/s&#39;</span>
    
    <span class="n">T0</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;T0&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
    <span class="n">T0</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;initial temperature&#39;</span>
    <span class="n">T0</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;T0&#39;</span>
    <span class="n">T0</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;K&#39;</span>
        
    <span class="n">K</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;K&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">K</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;mass transfer reduction factor&#39;</span>
    <span class="n">K</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;K&#39;</span>
    <span class="n">K</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>
    
    <span class="n">K_T</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;K_T&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">K_T</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;heat transfer reduction factor&#39;</span>
    <span class="n">K_T</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;K_T&#39;</span>
    <span class="n">K_T</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>
    
    <span class="n">fdis</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;fdis&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">fdis</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;dissolution criteria&#39;</span>
    <span class="n">fdis</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;fdis&#39;</span>
    <span class="n">fdis</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>
    
    <span class="n">t_hyd</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;t_hyd&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
    <span class="n">t_hyd</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;hydrate formation time&#39;</span>
    <span class="n">t_hyd</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;t_hyd&#39;</span>
    <span class="n">t_hyd</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;s&#39;</span>
    
    <span class="c1"># Check if these are plume particle objects</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">particles</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">integrate</span>
        <span class="c1"># Must be bent_plume_model.Particle object</span>
        <span class="n">particle_type</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">2</span>
        <span class="n">nb0</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;nb0&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">nb0</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;initial bubble number flux&#39;</span>
        <span class="n">nb0</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;nb0&#39;</span>
        <span class="n">nb0</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;s^(-1)&#39;</span>
        
        <span class="n">nbe</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;nbe&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">nbe</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;number of bubbles following plume element&#39;</span>
        <span class="n">nbe</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;nbe&#39;</span>
        <span class="n">nbe</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;count&#39;</span>
        
        <span class="n">lambda_1</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;lambda_1&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">lambda_1</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;bubble spreading ratio&#39;</span>
        <span class="n">lambda_1</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;lambda_1&#39;</span>
        <span class="n">lambda_1</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>
        
        <span class="n">integrate</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;integrate&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
        <span class="n">integrate</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;Particle status (0: false, 1: true)&#39;</span>
        <span class="n">integrate</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;integrate&#39;</span>
        <span class="n">integrate</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;boolean&#39;</span>
        
        <span class="n">sim_stored</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;sim_stored&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
        <span class="n">sim_stored</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;Tracking state (0: false, 1: true)&#39;</span>
        <span class="n">sim_stored</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;sim_stored&#39;</span>
        <span class="n">sim_stored</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;boolean&#39;</span>
        
        <span class="n">farfield</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;farfield&#39;</span><span class="p">,</span> <span class="s1">&#39;i4&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,))</span>
        <span class="n">farfield</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;Farfield simualtion (0: false, 1: true)&#39;</span>
        <span class="n">farfield</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;farfield&#39;</span>
        <span class="n">farfield</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;boolean&#39;</span>
        
        <span class="n">tp</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;tp&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">tp</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;time&#39;</span>
        <span class="n">tp</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;t&#39;</span>
        <span class="n">tp</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;s&#39;</span>
        
        <span class="n">xp</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;xp&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">xp</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;x-coordinate&#39;</span>
        <span class="n">xp</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;x&#39;</span>
        <span class="n">xp</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m&#39;</span>
        
        <span class="n">yp</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;yp&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">yp</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;y-coordinate&#39;</span>
        <span class="n">yp</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;y&#39;</span>
        <span class="n">yp</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m&#39;</span>
        
        <span class="n">zp</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;zp&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">zp</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;z-coordinate&#39;</span>
        <span class="n">zp</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;z&#39;</span>
        <span class="n">zp</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m&#39;</span>
        <span class="n">zp</span><span class="o">.</span><span class="n">axis</span> <span class="o">=</span> <span class="s1">&#39;Z&#39;</span>
        <span class="n">zp</span><span class="o">.</span><span class="n">positive</span> <span class="o">=</span> <span class="s1">&#39;down&#39;</span>
         
        <span class="n">te</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;te&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">te</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;particle exit time&#39;</span>
        <span class="n">te</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;te&#39;</span>
        <span class="n">te</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;s&#39;</span>
        
        <span class="n">xe</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;xe&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">xe</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;particle exit x-coordinate&#39;</span>
        <span class="n">xe</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;xe&#39;</span>
        <span class="n">xe</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m&#39;</span>
        
        <span class="n">ye</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;ye&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">ye</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;particle exit y-coordinate&#39;</span>
        <span class="n">ye</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;ye&#39;</span>
        <span class="n">ye</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m&#39;</span>
        
        <span class="n">ze</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;ze&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
        <span class="n">ze</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;particle exit z-coordinate&#39;</span>
        <span class="n">ze</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;ze&#39;</span>
        <span class="n">ze</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m&#39;</span>
        <span class="n">ze</span><span class="o">.</span><span class="n">axis</span> <span class="o">=</span> <span class="s1">&#39;Z&#39;</span>
        <span class="n">ze</span><span class="o">.</span><span class="n">positive</span> <span class="o">=</span> <span class="s1">&#39;down&#39;</span>
    
    <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">particles</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">nb0</span>
            <span class="c1"># Must be PlumeParticle object</span>
            <span class="n">particle_type</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="n">nb0</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;nb0&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
            <span class="n">nb0</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;initial bubble number flux&#39;</span>
            <span class="n">nb0</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;nb0&#39;</span>
            <span class="n">nb0</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;s^(-1)&#39;</span>
            
            <span class="n">lambda_1</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;lambda_1&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">))</span>
            <span class="n">lambda_1</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;bubble spreading ratio&#39;</span>
            <span class="n">lambda_1</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;lambda_1&#39;</span>
            <span class="n">lambda_1</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>
        
        <span class="k">except</span> <span class="ne">AttributeError</span><span class="p">:</span>
            <span class="n">particle_type</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
   
    <span class="c1"># Check if we need to reserve space to store an external chemical data</span>
    <span class="c1"># base of user_data</span>
    <span class="n">next_chems</span> <span class="o">=</span> <span class="mi">0</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">)):</span>
        <span class="k">if</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">issoluble</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">user_data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">next_chems</span><span class="p">:</span>
                <span class="n">next_chems</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">user_data</span><span class="p">)</span>
                <span class="c1"># Python 3 will not index a dict_keys() object because that</span>
                <span class="c1"># is not a good thing to do.  However, that is what we do</span>
                <span class="c1"># below...hence, we need to make the dict_keys into a list</span>
                <span class="n">user_composition</span> <span class="o">=</span> \
                    <span class="nb">list</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">user_data</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
    
    <span class="k">if</span> <span class="n">next_chems</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">next_chems</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createDimension</span><span class="p">(</span><span class="s1">&#39;next_chems&#39;</span><span class="p">,</span> <span class="n">next_chems</span><span class="p">)</span>
        <span class="n">nc</span><span class="o">.</span><span class="n">user_composition</span> <span class="o">=</span> <span class="s1">&#39; &#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">user_composition</span><span class="p">)</span>
        <span class="n">M</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;M&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">M</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;molecular weight&#39;</span>
        <span class="n">M</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;M&#39;</span>
        <span class="n">M</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;kg/mol&#39;</span>
        
        <span class="n">Pc</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;Pc&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">Pc</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;pressure at the critical point&#39;</span>
        <span class="n">Pc</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;Pc&#39;</span>
        <span class="n">Pc</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;Pa&#39;</span>
        
        <span class="n">Tc</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;Tc&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">Tc</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;temperature at the critical point&#39;</span>
        <span class="n">Tc</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;Tc&#39;</span>
        <span class="n">Tc</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;K&#39;</span>
        
        <span class="n">Vc</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;Vc&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">Vc</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;molar volume at the critical point&#39;</span>
        <span class="n">Vc</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;Vc&#39;</span>
        <span class="n">Vc</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m^3/mol&#39;</span>
        
        <span class="n">Tb</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;Tb&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">Tb</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;boiling point&#39;</span>
        <span class="n">Tb</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;Tb&#39;</span>
        <span class="n">Tb</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;K&#39;</span>
        
        <span class="n">Vb</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;Vb&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">Vb</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;molar volume at the boiling point&#39;</span>
        <span class="n">Vb</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;Vb&#39;</span>
        <span class="n">Vb</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m^3/mol&#39;</span>
        
        <span class="n">omega</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;omega&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> 
            <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">omega</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;acentric factor&#39;</span>
        <span class="n">omega</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;omega&#39;</span>
        <span class="n">omega</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;nondimensional&#39;</span>
        
        <span class="n">kh_0</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;kh_0&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">kh_0</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;Henrys law constant at 298.15 K&#39;</span>
        <span class="n">kh_0</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;kh_0&#39;</span>
        <span class="n">kh_0</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;kg/(m^3 Pa)&#39;</span>
        
        <span class="n">neg_dH_solR</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;neg_dH_solR&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> 
            <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">neg_dH_solR</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;negative of the enthalpy of solution / R&#39;</span>
        <span class="n">neg_dH_solR</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;neg_dH_solR&#39;</span>
        <span class="n">neg_dH_solR</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;K&#39;</span>
        
        <span class="n">nu_bar</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;nu_bar&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> 
            <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">nu_bar</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;specific volume at infinite dilution&#39;</span>
        <span class="n">nu_bar</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;nu_bar&#39;</span>
        <span class="n">nu_bar</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m^3/mol&#39;</span>
        
        <span class="n">B</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;B&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">B</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;diffusivity model coefficient B&#39;</span>
        <span class="n">B</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;B&#39;</span>
        <span class="n">B</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m^2/s&#39;</span>
        
        <span class="n">dE</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;dE&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">dE</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;diffusivity model coefficient dE&#39;</span>
        <span class="n">dE</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;dE&#39;</span>
        <span class="n">dE</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;J/mol&#39;</span>
        
        <span class="n">K_salt</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">createVariable</span><span class="p">(</span><span class="s1">&#39;K_salt&#39;</span><span class="p">,</span> <span class="s1">&#39;f8&#39;</span><span class="p">,</span> <span class="p">(</span><span class="s1">&#39;nparticles&#39;</span><span class="p">,</span> 
            <span class="s1">&#39;next_chems&#39;</span><span class="p">))</span>
        <span class="n">K_salt</span><span class="o">.</span><span class="n">long_name</span> <span class="o">=</span> <span class="s1">&#39;Setschenow salting out correction for solubility&#39;</span>
        <span class="n">K_salt</span><span class="o">.</span><span class="n">standard_name</span> <span class="o">=</span> <span class="s1">&#39;K_salt&#39;</span>
        <span class="n">K_salt</span><span class="o">.</span><span class="n">units</span> <span class="o">=</span> <span class="s1">&#39;m^3/mol&#39;</span>
    
    <span class="c1"># Store the values for each particle in the list</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">)):</span>
        
        <span class="c1"># Store the variables needed to create dbm particle objects</span>
        <span class="k">if</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">issoluble</span><span class="p">:</span>
            <span class="n">issoluble</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="n">isfluid</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="n">isair</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">isair</span>
            <span class="n">iscompressible</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="n">fp_type</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">fp_type</span>
            <span class="n">calc_delta</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">calc_delta</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">user_data</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
                <span class="n">extern_data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">extern_data</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
                <span class="n">user_data</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">user_data</span>
                <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">user_composition</span><span class="p">)):</span>
                    <span class="n">M</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;M&#39;</span><span class="p">]</span>
                    <span class="n">Pc</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Pc&#39;</span><span class="p">]</span>
                    <span class="n">Tc</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Tc&#39;</span><span class="p">]</span>
                    <span class="n">Vc</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Vc&#39;</span><span class="p">]</span>
                    <span class="n">Tb</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Tb&#39;</span><span class="p">]</span>
                    <span class="n">Vb</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Vb&#39;</span><span class="p">]</span>
                    <span class="n">omega</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;omega&#39;</span><span class="p">]</span>
                    <span class="n">kh_0</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;kh_0&#39;</span><span class="p">]</span>
                    <span class="n">neg_dH_solR</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;-dH_solR&#39;</span><span class="p">]</span>
                    <span class="n">nu_bar</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;nu_bar&#39;</span><span class="p">]</span>
                    <span class="n">B</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;B&#39;</span><span class="p">]</span>
                    <span class="n">dE</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;dE&#39;</span><span class="p">]</span>
                    <span class="n">K_salt</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;K_salt&#39;</span><span class="p">]</span>
            <span class="n">sigma_correction</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">sigma_correction</span>
            <span class="k">if</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">calc_delta</span><span class="p">:</span>
                <span class="n">delta_groups</span><span class="p">[</span><span class="n">i</span><span class="p">,:,:]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">delta_groups</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">delta_groups</span><span class="p">[</span><span class="n">i</span><span class="p">,:,:]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">((</span><span class="nb">len</span><span class="p">(</span><span class="n">chem_names</span><span class="p">),</span><span class="mi">15</span><span class="p">))</span>
            <span class="n">m0</span><span class="p">[</span><span class="n">i</span><span class="p">,:]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">m0</span>
            <span class="n">rho_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.</span>
            <span class="n">gamma</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.</span>
            <span class="n">beta</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.</span>
            <span class="n">co</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mf">1.</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">issoluble</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">isair</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">if</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">isfluid</span><span class="p">:</span>
                <span class="n">isfluid</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">isfluid</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">if</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">iscompressible</span><span class="p">:</span>
                <span class="n">iscompressible</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">iscompressible</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="n">fp_type</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mi">3</span>
            <span class="n">calc_delta</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
            <span class="n">sigma_correction</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1.</span>
            <span class="n">m0</span><span class="p">[</span><span class="n">i</span><span class="p">,</span><span class="mi">0</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">m0</span>
            <span class="n">rho_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">rho_p</span>
            <span class="n">gamma</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">gamma</span>
            <span class="n">beta</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">beta</span>
            <span class="n">co</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">co</span>
        
        <span class="c1"># Store the variables needed to create dispersed_phases SingleParticle</span>
        <span class="c1"># or PlumeParticle objects</span>
        <span class="n">T0</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">T0</span>
        <span class="n">K</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">K</span>
        <span class="n">K_T</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">K_T0</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
        <span class="n">fdis</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">fdis</span>
        <span class="n">t_hyd</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">t_hyd</span>
        
        <span class="k">if</span> <span class="n">particle_type</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span> <span class="ow">or</span> <span class="n">particle_type</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">nb0</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">nb0</span>
            <span class="n">lambda_1</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">lambda_1</span>
        
        <span class="k">if</span> <span class="n">particle_type</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="n">nb0</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">nb0</span>
            <span class="n">nbe</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">nbe</span>
            <span class="n">lambda_1</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">lambda_1</span>
            <span class="n">integrate</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">integrate</span>
            <span class="n">sim_stored</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">sim_stored</span>
            <span class="n">farfield</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">farfield</span>
            <span class="n">tp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">t</span>
            <span class="n">xp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">x</span>
            <span class="n">yp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">y</span>
            <span class="n">zp</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">z</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">te</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">te</span>
                <span class="n">xe</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">xe</span>
                <span class="n">ye</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">ye</span>
                <span class="n">ze</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">ze</span>
            <span class="k">except</span><span class="p">:</span>
                <span class="k">pass</span></div>

<div class="viewcode-block" id="load_particle_from_nc_file"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.load_particle_from_nc_file.html#dispersed_phases.load_particle_from_nc_file">[docs]</a><span class="k">def</span> <span class="nf">load_particle_from_nc_file</span><span class="p">(</span><span class="n">nc</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Read the complete `particles` list from a netCDF output file</span>
<span class="sd">    </span>
<span class="sd">    Creates the `particles` list of `SingleParticle`, `PlumeParticle`, or</span>
<span class="sd">    `bent_plume_model.Particle` objects from the attributes stored in a </span>
<span class="sd">    netCDF output file.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    nc : `netCDF4.Dataset` object</span>
<span class="sd">        A `netCDF4.Dataset` object that is open and where the particle </span>
<span class="sd">        attributes should be written</span>
<span class="sd">    particle_type : int</span>
<span class="sd">        The particle type is either 0: `SingleParticle`, 1: `PlumeParticle`</span>
<span class="sd">        or 2: `bent_plume_model.Particle`</span>
<span class="sd">    X0 : ndarray</span>
<span class="sd">        Vector of initial positions for the `bent_plume_model.Particle` </span>
<span class="sd">        objects.</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># All particles have the same composition</span>
    <span class="n">chem_names</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">composition</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
    
    <span class="c1"># Load each particle object separately</span>
    <span class="n">particles</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">dimensions</span><span class="p">[</span><span class="s1">&#39;nparticles&#39;</span><span class="p">])):</span>
        
        <span class="c1"># Create the correct dbm object</span>
        <span class="k">if</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;issoluble&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]:</span>
            <span class="k">if</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;extern_data&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]:</span>
                <span class="n">user_data</span> <span class="o">=</span> <span class="p">{}</span>
                <span class="n">user_composition</span> <span class="o">=</span> <span class="nb">str</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">user_composition</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
                <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">user_composition</span><span class="p">)):</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]]</span> <span class="o">=</span> <span class="p">{}</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;M&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;M&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Pc&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Pc&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Tc&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Tc&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Vc&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Vc&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Tb&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Tb&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;Vb&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Vb&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;omega&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;omega&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;kh_0&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;kh_0&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;-dH_solR&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;neg_dH_solR&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;nu_bar&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;nu_bar&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;B&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;B&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;dE&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;dE&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
                    <span class="n">user_data</span><span class="p">[</span><span class="n">user_composition</span><span class="p">[</span><span class="n">j</span><span class="p">]][</span><span class="s1">&#39;K_salt&#39;</span><span class="p">]</span> <span class="o">=</span> \
                        <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;K_salt&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="n">j</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">user_data</span> <span class="o">=</span> <span class="p">{}</span>
            <span class="k">if</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;calc_delta&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]:</span>
                <span class="n">delta_groups</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;delta_groups&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,:,:]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">delta_groups</span> <span class="o">=</span> <span class="kc">None</span>
            <span class="n">particle</span> <span class="o">=</span> <span class="n">dbm</span><span class="o">.</span><span class="n">FluidParticle</span><span class="p">(</span><span class="n">chem_names</span><span class="p">,</span> 
                <span class="n">fp_type</span><span class="o">=</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;fp_type&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">user_data</span><span class="o">=</span><span class="n">user_data</span><span class="p">,</span> 
                <span class="n">delta_groups</span><span class="o">=</span><span class="n">delta_groups</span><span class="p">,</span> 
                <span class="n">isair</span><span class="o">=</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;isair&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">sigma_correction</span><span class="o">=</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;sigma_correction&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">])</span>
            <span class="n">m0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;m0&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,:])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;isfluid&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]:</span>
                <span class="n">isfluid</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">isfluid</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="k">if</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;iscompressible&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]:</span>
                <span class="n">iscompressible</span> <span class="o">=</span> <span class="kc">True</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">iscompressible</span> <span class="o">=</span> <span class="kc">False</span>
            <span class="n">particle</span> <span class="o">=</span> <span class="n">dbm</span><span class="o">.</span><span class="n">InsolubleParticle</span><span class="p">(</span><span class="n">isfluid</span><span class="p">,</span> <span class="n">iscompressible</span><span class="p">,</span> 
                <span class="n">rho_p</span><span class="o">=</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;rho_p&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">gamma</span><span class="o">=</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;gamma&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">beta</span><span class="o">=</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;beta&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">co</span><span class="o">=</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;co&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">])</span>
            <span class="n">m0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;m0&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">,</span><span class="mi">0</span><span class="p">]])</span>
        
        <span class="c1"># Create the right dispersed_phases object</span>
        <span class="k">if</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;particle_type&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span><span class="p">:</span>
            <span class="kn">from</span> <span class="nn">tamoc</span> <span class="kn">import</span> <span class="n">bent_plume_model</span> <span class="k">as</span> <span class="n">bpm</span>
            <span class="n">particle</span> <span class="o">=</span> <span class="n">bpm</span><span class="o">.</span><span class="n">Particle</span><span class="p">(</span><span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;xp&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;yp&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;zp&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">particle</span><span class="p">,</span> <span class="n">m0</span><span class="p">,</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;T0&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;nb0&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;lambda_1&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;P&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Sa&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Ta&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;K&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;K_T&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;fdis&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;t_hyd&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">])</span>
            <span class="n">particle</span><span class="o">.</span><span class="n">nbe</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;nbe&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
            <span class="n">particle</span><span class="o">.</span><span class="n">t</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;tp&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
            <span class="n">particle</span><span class="o">.</span><span class="n">integrate</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;integrate&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
            <span class="n">particle</span><span class="o">.</span><span class="n">sim_stored</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;sim_stored&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
            <span class="n">particle</span><span class="o">.</span><span class="n">farfield</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;farfield&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
            <span class="k">if</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;te&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span> <span class="o">&gt;</span> <span class="mf">0.</span><span class="p">:</span>
                <span class="n">particle</span><span class="o">.</span><span class="n">te</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;te&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
                <span class="n">particle</span><span class="o">.</span><span class="n">xe</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;xe&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
                <span class="n">particle</span><span class="o">.</span><span class="n">ye</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;ye&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
                <span class="n">particle</span><span class="o">.</span><span class="n">ze</span> <span class="o">=</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;ze&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">]</span>
                
        <span class="k">elif</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;particle_type&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="n">particle</span>  <span class="o">=</span> <span class="n">PlumeParticle</span><span class="p">(</span><span class="n">particle</span><span class="p">,</span> <span class="n">m0</span><span class="p">,</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;T0&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;nb0&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;lambda_1&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;P&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Sa&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;Ta&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;K&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;K_T&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;fdis&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;t_hyd&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">particle</span>  <span class="o">=</span> <span class="n">SingleParticle</span><span class="p">(</span><span class="n">particle</span><span class="p">,</span> <span class="n">m0</span><span class="p">,</span> 
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;T0&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;K&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;K_T&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span> <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;fdis&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">],</span>
                <span class="n">nc</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;t_hyd&#39;</span><span class="p">][</span><span class="n">i</span><span class="p">])</span>
        
        <span class="c1"># Add this particle to the particles list</span>
        <span class="n">particles</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">particle</span><span class="p">)</span>
    
    <span class="c1"># Return the list of particles and their composition</span>
    <span class="k">return</span> <span class="p">(</span><span class="n">particles</span><span class="p">,</span> <span class="n">chem_names</span><span class="p">)</span></div>


<span class="c1"># ----------------------------------------------------------------------------</span>
<span class="c1"># Functions for shear entrainment</span>
<span class="c1"># ----------------------------------------------------------------------------</span>

<div class="viewcode-block" id="shear_entrainment"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.shear_entrainment.html#dispersed_phases.shear_entrainment">[docs]</a><span class="k">def</span> <span class="nf">shear_entrainment</span><span class="p">(</span><span class="n">U</span><span class="p">,</span> <span class="n">Us</span><span class="p">,</span> <span class="n">rho</span><span class="p">,</span> <span class="n">rho_a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">sin_p</span><span class="p">,</span> <span class="n">p</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Compute the entrainment coefficient for shear entrainment </span>
<span class="sd">    </span>
<span class="sd">    Computes the entrainment coefficient for the shear entrainment for a top</span>
<span class="sd">    hat model.  This code can be used by both the bent plume model and the </span>
<span class="sd">    stratified plume model.  It is based on the concepts for shear entrainment</span>
<span class="sd">    in Lee and Cheung (1990) and adapted by the model in Jirka (2004).  The</span>
<span class="sd">    model works for pure jets, pure plumes, and buoyant jets.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    U : float</span>
<span class="sd">        Top hat velocity of entrained plume water (m/s)</span>
<span class="sd">    Us : float</span>
<span class="sd">        Component of the ambient current projected along the plume </span>
<span class="sd">        centerline (m/s)</span>
<span class="sd">    rho : float</span>
<span class="sd">        Density of the entrained plume fluid (kg/m^3)</span>
<span class="sd">    rho_a : float</span>
<span class="sd">        Density of the ambient water at the current height (kg/m^3)</span>
<span class="sd">    sin_p : float</span>
<span class="sd">        Sine of the angle phi from the horizontal with down being positive (up </span>
<span class="sd">        is - pi/2)</span>
<span class="sd">        Cosine of the angle theta from the crossflow direction</span>
<span class="sd">    p : `bent_plume_model.ModelParams` or `stratified_plume_model.ModelParams`</span>
<span class="sd">        Object containing the present model parameters</span>
<span class="sd">    </span>
<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    alpha_s : float</span>
<span class="sd">        The shear entrainment coefficient (--)</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Gaussian model jet entrainment coefficient</span>
    <span class="n">alpha_j</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">alpha_j</span>
    
    <span class="c1"># Gaussian model plume entrainment coefficient</span>
    <span class="k">if</span> <span class="n">rho_a</span> <span class="o">==</span> <span class="n">rho</span><span class="p">:</span>
        <span class="c1"># This is a pure jet</span>
        <span class="n">alpha_p</span> <span class="o">=</span> <span class="mf">0.</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="c1"># This is a plume; compute the densimetric Gaussian Froude number</span>
        <span class="n">F1</span> <span class="o">=</span> <span class="mf">2.</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">U</span> <span class="o">-</span> <span class="n">Us</span><span class="p">)</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">g</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">rho_a</span> <span class="o">-</span> <span class="n">rho</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="mf">1.</span> <span class="o">+</span> 
             <span class="mf">1.2</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span> <span class="o">/</span> <span class="mf">1.2</span><span class="o">**</span><span class="mi">2</span> <span class="o">/</span> <span class="n">rho_a</span> <span class="o">*</span> <span class="n">b</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mf">2.</span><span class="p">))</span>
        
        <span class="c1"># Follow Figure 13 in Jirka (2004)</span>
        <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">F1</span><span class="o">**</span><span class="mi">2</span> <span class="o">/</span> <span class="n">sin_p</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">p</span><span class="o">.</span><span class="n">alpha_Fr</span> <span class="o">/</span> <span class="mf">0.028</span><span class="p">:</span>
            <span class="n">alpha_p</span> <span class="o">=</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">rho_a</span> <span class="o">-</span> <span class="n">rho</span><span class="p">)</span> <span class="o">*</span> <span class="n">p</span><span class="o">.</span><span class="n">alpha_Fr</span> <span class="o">*</span> <span class="n">sin_p</span> <span class="o">/</span> <span class="n">F1</span><span class="o">**</span><span class="mi">2</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">alpha_p</span> <span class="o">=</span> <span class="o">-</span> <span class="p">(</span><span class="mf">0.083</span> <span class="o">-</span> <span class="n">p</span><span class="o">.</span><span class="n">alpha_j</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">p</span><span class="o">.</span><span class="n">alpha_Fr</span> <span class="o">/</span> <span class="mf">0.028</span><span class="p">)</span> <span class="o">*</span> <span class="n">F1</span><span class="o">**</span><span class="mi">2</span> <span class="o">/</span> \
                      <span class="n">sin_p</span> <span class="o">*</span> <span class="n">np</span><span class="o">.</span><span class="n">sign</span><span class="p">(</span><span class="n">rho_a</span> <span class="o">-</span> <span class="n">rho</span><span class="p">)</span>
    
    <span class="c1"># Compute the total shear entrainment coefficient for the top-hat model</span>
    <span class="k">if</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">U</span> <span class="o">-</span> <span class="n">Us</span><span class="p">)</span> <span class="o">+</span> <span class="n">U</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
        <span class="n">alpha_s</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mf">2.</span><span class="p">)</span> <span class="o">*</span> <span class="n">alpha_j</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">alpha_s</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mf">2.</span><span class="p">)</span> <span class="o">*</span> <span class="p">(</span><span class="n">alpha_j</span> <span class="o">+</span> <span class="n">alpha_p</span><span class="p">)</span> <span class="o">*</span> <span class="mf">2.</span> <span class="o">*</span> <span class="n">U</span> <span class="o">/</span> \
                  <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">abs</span><span class="p">(</span><span class="n">U</span> <span class="o">-</span> <span class="n">Us</span><span class="p">)</span> <span class="o">+</span> <span class="n">U</span><span class="p">)</span>
    
    <span class="c1"># Return the total shear entrainment coefficient</span>
    <span class="k">return</span> <span class="n">alpha_s</span></div>


<span class="c1"># ----------------------------------------------------------------------------</span>
<span class="c1"># Functions for hydrate skin model</span>
<span class="c1"># ----------------------------------------------------------------------------</span>

<div class="viewcode-block" id="hydrate_formation_time"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.hydrate_formation_time.html#dispersed_phases.hydrate_formation_time">[docs]</a><span class="k">def</span> <span class="nf">hydrate_formation_time</span><span class="p">(</span><span class="n">dbm_obj</span><span class="p">,</span> <span class="n">z</span><span class="p">,</span> <span class="n">m</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">profile</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Compute the hydrate formation time</span>
<span class="sd">    </span>
<span class="sd">    Computes the time to form a hydrate shell using the empirical model from</span>
<span class="sd">    Jun et al. (2015).  If the particle is above the hydrate stability zone,</span>
<span class="sd">    the formation time is np.inf.  If it is below the hydrate statbility</span>
<span class="sd">    line, the maximum formation time t_star is computed based on the particle</span>
<span class="sd">    diameter.  For high hydrate subcooling, the formation time can be </span>
<span class="sd">    accelerated by a factor phi = f(extent of subcooling).  The final </span>
<span class="sd">    hydrate formation time is t_hyd = phi * t_star.</span>
<span class="sd">    </span>
<span class="sd">    The idea behind this model is that bubbles or droplets in the ocen may </span>
<span class="sd">    form a hydrate shell that results in dirty-bubble mass and heat transfer</span>
<span class="sd">    and rise velocity.  This algorithm sets the time to form the shell based</span>
<span class="sd">    on measured field data by Rehder et al. (2002).  The model has been </span>
<span class="sd">    validated to field data in Romer et al. (2012), McGinnis et al. (2006), </span>
<span class="sd">    Warkinski et al. (2014), and the GISR field experiments.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    dbm_obj : `dbm.FluidParticle` object</span>
<span class="sd">        Discrete bubble model `dbm.FluidParticle` object.  Since this method</span>
<span class="sd">        must calculate the hydrate stability temperature, it cannot be used</span>
<span class="sd">        on `dbm.InsolubleParticle` objects.  A hydrate formation time can </span>
<span class="sd">        still be set for those particles, but not estimated from this </span>
<span class="sd">        function.</span>
<span class="sd">    z : float</span>
<span class="sd">        Release depth (m)</span>
<span class="sd">    m : ndarray</span>
<span class="sd">        Initial masses of the components of the `dbm_obj` (kg)</span>
<span class="sd">    T : float</span>
<span class="sd">        Initial temperature of the of `dbm~_obj` particle (K)</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        An object containing the ambient CTD data and associated methods.  </span>
<span class="sd">    </span>
<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    t_hyd : float</span>
<span class="sd">        Hydrate formation time (s)</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Get the ambient properties at the depth</span>
    <span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="n">z</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;temperature&#39;</span><span class="p">,</span> <span class="s1">&#39;salinity&#39;</span><span class="p">,</span> 
                                   <span class="s1">&#39;pressure&#39;</span><span class="p">])</span>
    
    <span class="c1"># Compute the diameter of the particle</span>
    <span class="n">de</span> <span class="o">=</span> <span class="n">dbm_obj</span><span class="o">.</span><span class="n">diameter</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">)</span>
    
    <span class="c1"># Estimate the hydrate stability temperature</span>
    <span class="n">T_hyd</span> <span class="o">=</span> <span class="n">dbm_obj</span><span class="o">.</span><span class="n">hydrate_stability</span><span class="p">(</span><span class="n">m</span><span class="p">,</span> <span class="n">P</span><span class="p">)</span>
    
    <span class="k">if</span> <span class="n">T_hyd</span> <span class="o">&lt;</span> <span class="n">Ta</span><span class="p">:</span>
        <span class="c1"># The particle is above the hydrate stability zone...assume hydrates</span>
        <span class="c1"># never form.</span>
        <span class="n">t_hyd</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">inf</span>
    
    <span class="k">else</span><span class="p">:</span>
        <span class="c1"># The particle is below the hydrate stability zone, compute the </span>
        <span class="c1"># skin formation time.  </span>
        <span class="n">t_star</span> <span class="o">=</span> <span class="mf">85206.</span> <span class="o">*</span> <span class="n">de</span> <span class="o">-</span> <span class="mf">243.276</span>
        
        <span class="k">if</span> <span class="n">t_star</span> <span class="o">&lt;</span> <span class="mf">0.</span><span class="p">:</span>
            <span class="c1"># Hydate skin formation time cannot be zero.</span>
            <span class="n">t_star</span> <span class="o">=</span> <span class="mf">0.</span>
        
        <span class="c1"># Get the subcooling acceleration factor.</span>
        <span class="n">phi</span> <span class="o">=</span> <span class="o">-</span><span class="mf">0.1158</span> <span class="o">*</span> <span class="p">(</span><span class="n">T_hyd</span> <span class="o">-</span> <span class="n">Ta</span><span class="p">)</span> <span class="o">+</span> <span class="mf">2.2692</span>
        
        <span class="k">if</span> <span class="n">phi</span> <span class="o">&gt;</span> <span class="mf">1.</span><span class="p">:</span>
            <span class="c1"># Acceleration cannot be more than one.</span>
            <span class="n">phi</span> <span class="o">=</span> <span class="mf">1.</span>
            
        <span class="k">elif</span> <span class="n">phi</span> <span class="o">&lt;</span> <span class="mf">0.</span><span class="p">:</span>
            <span class="c1"># Acceleration cannot be less than 0.</span>
            <span class="n">phi</span> <span class="o">=</span> <span class="mf">0.</span>
        
        <span class="c1"># Compute the in situ hydrate formation time</span>
        <span class="n">t_hyd</span> <span class="o">=</span> <span class="n">phi</span> <span class="o">*</span> <span class="n">t_star</span>
    
    <span class="c1"># Return the formation time</span>
    <span class="k">return</span> <span class="n">t_hyd</span></div>


<span class="c1"># ----------------------------------------------------------------------------</span>
<span class="c1"># Functions to generate initial conditions for models using these objects</span>
<span class="c1"># ----------------------------------------------------------------------------</span>

<div class="viewcode-block" id="zfe_volume_flux"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.zfe_volume_flux.html#dispersed_phases.zfe_volume_flux">[docs]</a><span class="k">def</span> <span class="nf">zfe_volume_flux</span><span class="p">(</span><span class="n">profile</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">X0</span><span class="p">,</span> <span class="n">R</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Initial volume for a multiphase plume</span>
<span class="sd">    </span>
<span class="sd">    Uses the Wueest et al. (1992) plume Froude number method to estimate</span>
<span class="sd">    the amount of entrainment at the source of a dispersed phase plume with</span>
<span class="sd">    zero continuous phase flux (e.g., a pure bubble, droplet, or particle </span>
<span class="sd">    plume)</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    profile : `ambient.Profile` object</span>
<span class="sd">        The ambient CTD object used by the single bubble model simulation.</span>
<span class="sd">    particles : list of `Particle` objects</span>
<span class="sd">        List of `SingleParticle`, `PlumeParticle`, or </span>
<span class="sd">        `bent_plume_model.Particle` objects describing each dispersed phase </span>
<span class="sd">        in the simulation</span>
<span class="sd">    p : `stratified_plume_model.ModelParams` or `bent_plume_model.ModelParams`</span>
<span class="sd">        Object containing the fixed model parameters for one of the integral </span>
<span class="sd">        plume models</span>
<span class="sd">    X0 : float</span>
<span class="sd">        (x, y, depth) coordinates of the release point (m)</span>
<span class="sd">    R : float</span>
<span class="sd">        Radius of the equivalent circular area of the release (m)</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># The initial condition is valid at the diffuser (e.g., no virtual point</span>
    <span class="c1"># source for the Wuest et al. 1992 initial conditions).  Send back </span>
    <span class="c1"># exactly what the user supplied</span>
    <span class="n">X</span> <span class="o">=</span> <span class="n">X0</span>
    
    <span class="c1"># Get X0 as a three-dimensional vector for generality</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">X0</span><span class="p">,</span> <span class="n">np</span><span class="o">.</span><span class="n">ndarray</span><span class="p">):</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">X0</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
            <span class="n">X0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="n">X0</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">X0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">(</span><span class="n">X0</span><span class="p">)</span>
    
    <span class="c1"># Get the ambient conditions at the discharge</span>
    <span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span> <span class="o">=</span> <span class="n">profile</span><span class="o">.</span><span class="n">get_values</span><span class="p">(</span><span class="n">X0</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;temperature&#39;</span><span class="p">,</span> <span class="s1">&#39;salinity&#39;</span><span class="p">,</span> 
                                   <span class="s1">&#39;pressure&#39;</span><span class="p">])</span>
    <span class="n">rho</span> <span class="o">=</span> <span class="n">seawater</span><span class="o">.</span><span class="n">density</span><span class="p">(</span><span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span><span class="p">)</span>
    
    <span class="c1"># Update the particle objects and pull out the multiphase properties.</span>
    <span class="c1"># Since this is the release, the particle age is zero.</span>
    <span class="n">lambda_1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">))</span>
    <span class="n">us</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">))</span>
    <span class="n">rho_p</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">))</span>
    <span class="n">Q</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">)):</span>
        <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">m</span><span class="p">,</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">T</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="mf">0.</span><span class="p">)</span>
        <span class="n">lambda_1</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">lambda_1</span>
        <span class="n">us</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">us</span>
        <span class="n">rho_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">rho_p</span>
        <span class="n">Q</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">m</span><span class="p">)</span> <span class="o">*</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">nb0</span> <span class="o">/</span> <span class="n">rho_p</span><span class="p">[</span><span class="n">i</span><span class="p">]</span>
    
    <span class="c1"># Compute the buoyancy flux weighted average of lambda_1</span>
    <span class="n">lambda_ave</span> <span class="o">=</span> <span class="n">bf_average</span><span class="p">(</span><span class="n">particles</span><span class="p">,</span> <span class="n">rho</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">g</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">rho_r</span><span class="p">,</span> <span class="n">lambda_1</span><span class="p">)</span>
    
    <span class="c1"># Calculate the initial velocity of entrained ambient fluid</span>
    <span class="n">u_0</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">Q</span><span class="p">)</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="p">(</span><span class="n">lambda_ave</span> <span class="o">*</span> <span class="n">R</span><span class="p">)</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
    <span class="n">u</span> <span class="o">=</span> <span class="n">wuest_ic</span><span class="p">(</span><span class="n">u_0</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">lambda_1</span><span class="p">,</span> <span class="n">lambda_ave</span><span class="p">,</span> <span class="n">us</span><span class="p">,</span> <span class="n">rho_p</span><span class="p">,</span> <span class="n">rho</span><span class="p">,</span> <span class="n">Q</span><span class="p">,</span> <span class="n">R</span><span class="p">,</span> 
                 <span class="n">p</span><span class="o">.</span><span class="n">g</span><span class="p">,</span> <span class="n">p</span><span class="o">.</span><span class="n">Fr_0</span><span class="p">)</span>
    
    <span class="c1"># The initial plume width is the discharge port width</span>
    <span class="n">A</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">R</span><span class="o">**</span><span class="mi">2</span>
    
    <span class="c1"># Calcualte the volume flux</span>
    <span class="n">Q</span> <span class="o">=</span> <span class="n">A</span> <span class="o">*</span> <span class="n">u</span>
    
    <span class="k">return</span> <span class="p">(</span><span class="n">Q</span><span class="p">,</span> <span class="n">A</span><span class="p">,</span> <span class="n">X</span><span class="p">,</span> <span class="n">Ta</span><span class="p">,</span> <span class="n">Sa</span><span class="p">,</span> <span class="n">P</span><span class="p">,</span> <span class="n">rho</span><span class="p">)</span></div>


<div class="viewcode-block" id="wuest_ic"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.wuest_ic.html#dispersed_phases.wuest_ic">[docs]</a><span class="k">def</span> <span class="nf">wuest_ic</span><span class="p">(</span><span class="n">u_0</span><span class="p">,</span> <span class="n">particles</span><span class="p">,</span> <span class="n">lambda_1</span><span class="p">,</span> <span class="n">lambda_ave</span><span class="p">,</span> <span class="n">us</span><span class="p">,</span> <span class="n">rho_p</span><span class="p">,</span> <span class="n">rho</span><span class="p">,</span> <span class="n">Q</span><span class="p">,</span> <span class="n">R</span><span class="p">,</span> 
             <span class="n">g</span><span class="p">,</span> <span class="n">Fr_0</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Compute the initial velocity of entrained ambient fluid</span>
<span class="sd">    </span>
<span class="sd">    Computes the initial velocity of the entrained ambient fluid following </span>
<span class="sd">    the method in Wueest et al. (1992).  This method is implicit; thus, an </span>
<span class="sd">    initial guess for the velocity and a root-finding approach is required.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    u_0 : float</span>
<span class="sd">        Initial guess for the entrained fluid velocity (m/s)</span>
<span class="sd">    particles : list of `Particle` objects</span>
<span class="sd">        List of `SingleParticle`, `PlumeParticle`, or </span>
<span class="sd">        `bent_plume_model.Particle` objects describing each dispersed phase </span>
<span class="sd">        in the simulation</span>
<span class="sd">    lambda_1 : ndarray</span>
<span class="sd">        Spreading rate of the each dispersed phase particle in a plume (--)</span>
<span class="sd">    lambda_ave : float</span>
<span class="sd">        Buoyancy flux averaged value of lambda_1 (--)</span>
<span class="sd">    us : ndarray</span>
<span class="sd">        Slip velocity of each of the dispersed phase particles (m/s)</span>
<span class="sd">    rho_p : ndarray</span>
<span class="sd">        Density of each of the dispersed phase particles (kg/m^3)</span>
<span class="sd">    rho : float</span>
<span class="sd">        Density of the local ambient continuous phase fluid (kg/m^3)</span>
<span class="sd">    Q : ndarray</span>
<span class="sd">        Total volume flux of particles for each dispersed phase (m^3/s)</span>
<span class="sd">    R : float</span>
<span class="sd">        Radius of the release port (m)</span>
<span class="sd">    g : float</span>
<span class="sd">        Acceleration of gravity (m/s^2)</span>
<span class="sd">    Fr_0 : float</span>
<span class="sd">        Desired initial plume Froude number (--)</span>
<span class="sd">    </span>
<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    u : float</span>
<span class="sd">        The converged value of the entrained fluid velocity in m/s at the </span>
<span class="sd">        release location in order to achieve the specified value of Fr_0.</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># The Wuest et al. (1992) initial condition is implicit; define the </span>
    <span class="c1"># residual for use in a root-finding algorithm</span>
    <span class="k">def</span> <span class="nf">residual</span><span class="p">(</span><span class="n">u</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the residual of the Wueest et al. (1992) initial condition</span>
<span class="sd">        using the current guess for the initial velocity u.</span>
<span class="sd">        </span>
<span class="sd">        Parameters</span>
<span class="sd">        ----------</span>
<span class="sd">        u : float</span>
<span class="sd">            the current guess for the initial velocity (m/s)</span>
<span class="sd">        </span>
<span class="sd">        Notes</span>
<span class="sd">        -----</span>
<span class="sd">        All parameters of `wuest_ic` are global to this function since it is</span>
<span class="sd">        a subfunction of `wuest_ic`.</span>
<span class="sd">        </span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># Get the void fraction for the current estimate of the mixture of </span>
        <span class="c1"># dispersed phases and entrained ambient water</span>
        <span class="n">xi</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">)):</span>
            <span class="n">xi</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">Q</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">/</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="n">lambda_1</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span> <span class="o">*</span> <span class="n">R</span><span class="o">**</span><span class="mi">2</span> <span class="o">*</span> <span class="p">(</span><span class="n">us</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">+</span> 
                    <span class="mf">2.</span> <span class="o">*</span> <span class="n">u</span> <span class="o">/</span> <span class="p">(</span><span class="mf">1.</span> <span class="o">+</span> <span class="n">lambda_1</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">**</span><span class="mi">2</span><span class="p">)))</span>
        
        <span class="c1"># Get the mixed-fluid plume density</span>
        <span class="n">rho_m</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">xi</span> <span class="o">*</span> <span class="n">rho_p</span><span class="p">)</span> <span class="o">+</span> <span class="p">(</span><span class="mf">1.</span> <span class="o">-</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">xi</span><span class="p">))</span> <span class="o">*</span> <span class="n">rho</span>
        
        <span class="c1"># Calculate the deviation from the desired Froude number</span>
        <span class="k">return</span> <span class="n">Fr_0</span> <span class="o">-</span> <span class="n">u</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="mf">2.</span> <span class="o">*</span> <span class="n">lambda_ave</span> <span class="o">*</span> <span class="n">R</span> <span class="o">*</span> <span class="n">g</span> <span class="o">*</span> 
                                  <span class="p">(</span><span class="n">rho</span> <span class="o">-</span> <span class="n">rho_m</span><span class="p">)</span> <span class="o">/</span> <span class="n">rho_m</span><span class="p">)</span>
    
    <span class="k">return</span> <span class="n">fsolve</span><span class="p">(</span><span class="n">residual</span><span class="p">,</span> <span class="n">u_0</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span></div>


<div class="viewcode-block" id="bf_average"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.bf_average.html#dispersed_phases.bf_average">[docs]</a><span class="k">def</span> <span class="nf">bf_average</span><span class="p">(</span><span class="n">particles</span><span class="p">,</span> <span class="n">rho</span><span class="p">,</span> <span class="n">g</span><span class="p">,</span> <span class="n">rho_r</span><span class="p">,</span> <span class="n">parm</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Compute a buoyancy-flux-weighted average of `parm`</span>
<span class="sd">    </span>
<span class="sd">    Computes a weighted average of the values in `parm` using the kinematic</span>
<span class="sd">    buoyancy flux of each particle containing parm as the weight in the </span>
<span class="sd">    average calculation.  </span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    particles : list of `Particle` objects</span>
<span class="sd">        List of `SingleParticle`, `PlumeParticle`, or </span>
<span class="sd">        `bent_plume_model.Particle` objects describing each dispersed phase </span>
<span class="sd">        in the simulation</span>
<span class="sd">    rho : float</span>
<span class="sd">        Local density of ambient fluid outside plume (kg/m^3).</span>
<span class="sd">    g : float</span>
<span class="sd">        Acceleration of gravity (m/s^2).</span>
<span class="sd">    rho_r : float</span>
<span class="sd">        Model reference density (kg/m^3).</span>
<span class="sd">    parm : ndarray</span>
<span class="sd">        Numpy array of parameters to average, one value for each </span>
<span class="sd">        dispersed phase entry (same as elements in parm).</span>
<span class="sd">    </span>
<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    parm_ave : float</span>
<span class="sd">        The weighted average of `parm`.</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Compute the total buoyancy flux of each dispersed phase particle in the </span>
    <span class="c1"># simulation</span>
    <span class="n">F</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">)):</span>
        <span class="c1"># Get the total particle volume flux</span>
        <span class="n">Q</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">m</span><span class="p">)</span> <span class="o">*</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">nb0</span> <span class="o">/</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">rho_p</span>
        <span class="c1"># Compute the particle kinematic buoyancy flux</span>
        <span class="n">F</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">=</span> <span class="n">g</span> <span class="o">*</span> <span class="p">(</span><span class="n">rho</span> <span class="o">-</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">rho_p</span><span class="p">)</span> <span class="o">/</span> <span class="n">rho_r</span> <span class="o">*</span> <span class="n">Q</span>
    
    <span class="c1"># Return the buoyancy-flux-weighted value of parm</span>
    <span class="k">if</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">F</span><span class="p">)</span> <span class="o">==</span> <span class="mf">0.</span><span class="p">:</span>
        <span class="n">parm</span> <span class="o">=</span> <span class="mf">0.</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">parm</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">F</span> <span class="o">*</span> <span class="n">parm</span><span class="p">)</span> <span class="o">/</span> <span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">F</span><span class="p">)</span>
    
    <span class="k">return</span> <span class="n">parm</span></div>


<div class="viewcode-block" id="get_chem_names"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.get_chem_names.html#dispersed_phases.get_chem_names">[docs]</a><span class="k">def</span> <span class="nf">get_chem_names</span><span class="p">(</span><span class="n">particles</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Create a list of chemical names for the dispersed phase particles</span>
<span class="sd">    </span>
<span class="sd">    Reads the composition attribute of each particle in a `particles` list</span>
<span class="sd">    and compiles a unique list of particle names.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    particles : list of `Particle` objects</span>
<span class="sd">        List of `SingleParticle`, `PlumeParticle`, or </span>
<span class="sd">        `bent_plume_model.Particle` objects describing each dispersed phase </span>
<span class="sd">        in the simulation</span>
<span class="sd">    </span>
<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    chem_names : str list</span>
<span class="sd">        List of the chemical composition of particles undergoing dissolution</span>
<span class="sd">        in the `particles` list</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Initialize a list to store the names</span>
    <span class="n">chem_names</span> <span class="o">=</span> <span class="p">[]</span>
    
    <span class="c1"># Add the chemicals that are part of the particle composition</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">)):</span>
        <span class="k">if</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">particle</span><span class="o">.</span><span class="n">issoluble</span><span class="p">:</span>
            <span class="n">chem_names</span> <span class="o">+=</span> <span class="p">[</span><span class="n">chem</span> <span class="k">for</span> <span class="n">chem</span> <span class="ow">in</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">composition</span> <span class="k">if</span>
                           <span class="n">chem</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">chem_names</span><span class="p">]</span>
    
    <span class="c1"># Return the list of chemical names</span>
    <span class="k">return</span> <span class="n">chem_names</span></div>


<div class="viewcode-block" id="particles_state_space"><a class="viewcode-back" href="../autodoc/disp_phases/dispersed_phases.particles_state_space.html#dispersed_phases.particles_state_space">[docs]</a><span class="k">def</span> <span class="nf">particles_state_space</span><span class="p">(</span><span class="n">particles</span><span class="p">,</span> <span class="n">nb</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Create the state space describing the dispersed phase properties</span>
<span class="sd">    </span>
<span class="sd">    Constructs a complete state space of masses and heat content for all of</span>
<span class="sd">    the particles in the `particles` list.</span>
<span class="sd">    </span>
<span class="sd">    Parameters</span>
<span class="sd">    ----------</span>
<span class="sd">    particles : list of `Particle` objects</span>
<span class="sd">        List of `SingleParticle`, `PlumeParticle`, or </span>
<span class="sd">        `bent_plume_model.Particle` objects describing each dispersed phase </span>
<span class="sd">        in the simulation</span>
<span class="sd">    nb : ndarray</span>
<span class="sd">        Array of particle numbers for forming the state space.  nb can be in </span>
<span class="sd">        number/T, which will give state space variables in mass flux (M/T) or</span>
<span class="sd">        in number, which will give state space variables in mass.</span>
<span class="sd">    </span>
<span class="sd">    Returns</span>
<span class="sd">    -------</span>
<span class="sd">    y : ndarray</span>
<span class="sd">        Array of state space variables for the `particles` objects.</span>
<span class="sd">    </span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="c1"># Get the state variables of each particle, one particle as a time</span>
    <span class="n">y</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">particles</span><span class="p">)):</span>
        
        <span class="c1"># Masses of each element in the particle</span>
        <span class="n">y</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">m</span> <span class="o">*</span> <span class="n">nb</span><span class="p">[</span><span class="n">i</span><span class="p">])</span>
        
        <span class="c1"># Add in the heat flux of the particle</span>
        <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">(</span><span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">m</span><span class="p">)</span> <span class="o">*</span> <span class="n">nb</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> <span class="o">*</span> 
                 <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">cp</span> <span class="o">*</span> <span class="n">particles</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">.</span><span class="n">T</span><span class="p">)</span>
        
        <span class="c1"># Initialize the particle age to zero</span>
        <span class="n">y</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="mf">0.</span><span class="p">)</span>
        
        <span class="c1"># Initialize the particle positions to the center of the plume</span>
        <span class="n">y</span><span class="o">.</span><span class="n">extend</span><span class="p">([</span><span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">,</span> <span class="mf">0.</span><span class="p">])</span>
    
    <span class="c1"># Return the state space as a list</span>
    <span class="k">return</span> <span class="n">y</span></div>

</pre></div>

          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../index.html">Texas A&M Oil spill / Outfall Calculator</a></h1>








<h3>Navigation</h3>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../user_manual.html">TAMOC User Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../unit_tests.html">Unit Tests</a></li>
<li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../bugs.html">Reporting Bugs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../readme.html">Read Me File</a></li>
<li class="toctree-l1"><a class="reference internal" href="../release.html">Release Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../license.html">License</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../index.html">Documentation overview</a><ul>
  <li><a href="index.html">Module code</a><ul>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2020, Scott A. Socolofsky.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 2.4.4</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
    </div>

    

    
  </body>
</html>